//== SAGITTARIUS ============================================================================

//== BEGINNING OF CODE ===============================================================

#include "sagittarius/core/SagittariusCore.h"
#include "sagittarius/backend/llvm/llvmsupport.h"
#include "sagittarius/io/io.h"
#include <stdio.h>
#include <iostream>

namespace Sagittarius {
    
    void dump_arg_types(const std::vector<llvm::Value*>& args) {
        uint64 n=1;
        for(std::vector<llvm::Value*>::const_iterator i=args.begin(); i!=args.end(); ++i) {
            SG_WRITE(2, "arg ");
            sg_writeUInt64(2, n);
            SG_WRITE(2, ":\n");
            ++n;
            llvm::Value* v = *i;
            v->getType()->dump();
            SG_WRITE(2, "\n");
        }
    }
    
    int check_farg_types(llvm::Function* f, const std::vector<llvm::Value*>& args) {
        llvm::FunctionType* t = f->getFunctionType();
        llvm::FunctionType::param_iterator p=t->param_begin();
        std::vector<llvm::Value*>::const_iterator i=args.begin();
        for(; p!=t->param_end() && i!=args.end(); ++p, ++i) {
            if(*p != (*i)->getType()) {
                // dump signature
                SG_WRITE(2, "Function sig:\n");
                t->dump();
                SG_WRITE(2, "\n");
                dump_arg_types(args);
                return 0;
            }
        }
        if(p == t->param_end() && i == args.end())
            return 1;
        else {
            // dump signature
            SG_WRITE(2, "Function sig:\n");
            t->dump();
            SG_WRITE(2, "\n");
            dump_arg_types(args);
            return 0;
        }
    }
    
}
